package com.eva.captcha.api;

import com.eva.captcha.service.ImageCaptchaServiceImpl;
import com.eva.framework.captcha.model.ImageCaptcha;
import com.eva.framework.common.api.BaseController;
import com.eva.framework.common.model.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Api(tags = "图片验证码接口")
@RestController
@RequestMapping("/common")
public class ImageCaptchaController extends BaseController {

    @Resource
    private ImageCaptchaServiceImpl imageCaptchaWithCacheService;

    @ApiOperation("获取图片验证码")
    @GetMapping("/captcha/image")
    public ApiResponse<ImageCaptcha> getCaptcha(HttpServletRequest request) {
        // v5.1.0，支持根据主题生成图片验证码
        return ApiResponse.success(imageCaptchaWithCacheService.genCaptcha(this.getTheme(request)));
    }
}
